<template>
  <view class="container">
    <!-- 顶部标题区域 -->
    <view class="header">
      <view class="header-content">
        <text class="page-title">数据报表</text>
        <picker mode="selector" :range="dateRanges" @change="handleDateRangeChange">
          <view class="date-picker">
            {{ currentRange }}
          </view>
        </picker>
      </view>
    </view>

    <!-- 主要数据卡片 -->
    <view class="statistics">
      <view class="stat-grid">
        <view class="stat-card stat-sales">
          <text class="stat-label">销售总额</text>
          <text class="stat-value">¥{{ salesData.total }}</text>
          <text class="stat-growth">较上月 {{ salesData.growth }}</text>
        </view>
        <view class="stat-card stat-expense">
          <text class="stat-label">支出总额</text>
          <text class="stat-value">¥{{ expenseData.total }}</text>
          <text class="stat-growth">较上月 {{ expenseData.growth }}</text>
        </view>
      </view>
    </view>

    <!-- 图表区域 -->
    <view class="chart-area">
      <view class="chart-header">
        <text class="chart-title">销售趋势</text>
        <view class="chart-legend">
          <view class="legend-item">
            <view class="legend-dot sales-dot"></view>
            <text class="legend-text">销售额</text>
          </view>
          <view class="legend-item">
            <view class="legend-dot orders-dot"></view>
            <text class="legend-text">订单数</text>
          </view>
        </view>
      </view>
      <!-- 图表组件 -->
      <view class="chart-container">
        图表区域
      </view>
    </view>

    <!-- 热销商品列表 -->
    <view class="hot-sales">
      <text class="section-title">热销商品</text>
      <view class="product-list">
        <view v-for="(item, index) in hotSales" :key="index" class="product-item">
          <image :src="item.image" class="product-image"/>
          <view class="product-info">
            <view class="product-header">
              <text class="product-name">{{ item.name }}</text>
              <text class="product-sales">¥{{ item.sales }}</text>
            </view>
            <view class="product-stats">
              <text class="stat-text">销量：{{ item.quantity }}件</text>
              <text class="stat-text">占比：{{ item.percentage }}%</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'

// 日期范围选项
const dateRanges = ['本月', '上月', '近三月', '近半年']
const currentRange = ref('本月')

// 销售数据
const salesData = ref({
  total: '25,680',
  growth: '+12.5%'
})

// 支出数据
const expenseData = ref({
  total: '15,280',
  growth: '-5.2%'
})

// 热销商品数据
const hotSales = ref([
  {
    name: '运动鞋',
    image: 'https://images.unsplash.com/photo-1542291026-7eec264c27ff',
    sales: '8,970',
    quantity: 30,
    percentage: 35
  },
  {
    name: '智能手表',
    image: 'https://images.unsplash.com/photo-1523275335684-37898b6baf30',
    sales: '5,394',
    quantity: 18,
    percentage: 21
  }
])

// 处理日期范围变化
const handleDateRangeChange = (e) => {
  currentRange.value = dateRanges[e.detail.value]
  // TODO: 根据选择的日期范围更新数据
}
</script>

<style>
.container {
  min-height: 100vh;
  background-color: #F0F2F5;
  padding-top: var(--status-bar-height);
}

/* 头部样式 */
.header {
  background-color: #fff;
  padding: 16px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-title {
  font-size: 20px;
  font-weight: bold;
  color: #333;
}

.date-picker {
  font-size: 14px;
  background-color: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 8px 12px;
}

/* 统计卡片样式 */
.statistics {
  padding: 0 16px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  padding: 16px;
  border-radius: 16px;
  color: #fff;
}

.stat-sales {
  background-color: #10b981;
}

.stat-expense {
  background-color: #ef4444;
}

.stat-label {
  font-size: 14px;
  opacity: 0.9;
  margin-bottom: 4px;
  display: block;
}

.stat-value {
  font-size: 20px;
  font-weight: bold;
  display: block;
}

.stat-growth {
  font-size: 12px;
  opacity: 0.9;
  margin-top: 8px;
  display: block;
}

/* 图表区域样式 */
.chart-area {
  background-color: #fff;
  padding: 16px;
  margin: 0 16px;
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  margin-bottom: 24px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.chart-title {
  font-weight: 600;
  color: #333;
}

.chart-legend {
  display: flex;
  gap: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.sales-dot {
  background-color: #3b82f6;
}

.orders-dot {
  background-color: #10b981;
}

.legend-text {
  font-size: 12px;
  color: #666;
}

.chart-container {
  height: 160px;
  background-color: #f9fafb;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
}

/* 热销商品列表样式 */
.hot-sales {
  background-color: #fff;
  padding: 16px;
  margin: 0 16px;
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.section-title {
  font-weight: 600;
  color: #333;
  margin-bottom: 16px;
  display: block;
}

.product-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.product-item {
  display: flex;
  align-items: center;
}

.product-image {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  margin-right: 12px;
}

.product-info {
  flex: 1;
}

.product-header {
  display: flex;
  justify-content: space-between;
}

.product-name {
  font-weight: 500;
  color: #333;
}

.product-sales {
  color: #10b981;
}

.product-stats {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
}

.stat-text {
  font-size: 14px;
  color: #666;
}
</style> 